<style scoped>
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }

  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }

  .rj-cell.max span {
    font-size: 16px;
    padding-right: 20px;
  }

  .rj-cell label {
    color: #333;
    font-size: 14px;
    width: 44%;
    display: inline-block;
    padding: 5px 3%;
    text-align: right;
  }

  .rj-cell span {
    font-size: 14px;
    color: #333;
    display: inline-block;
    width: 50%;
  }

  .rj-cell.note label {
    float: left;
  }

  .rj-cell.note span {
    width: 80%;
    display: inline-block;
  }

  .weui-cells {
    margin-top: 0;
  }

  .weui-cells_form {
    background: #fbfbfb;
  }

  .weui-cell {
    background: #fff;
  }

  .weui-cells__title {
    text-align: left;
  }

  .oitem {
    padding: 3px;
  }

  .hide {
    display: none;
  }

  #acts {
    font-size: 0;
  }

  #acts span {
    font-size: 14px;
  }

  .halfbtn {
    display: inline-block;
    width: 49%;
  }

  .weui-label {
    text-align: left;
  }

  .time {
    border: none;
    font-size: 17px;
  }

  .weui-cell_select {
    padding: 10px 15px;
  }

  .weui-select {
    height: auto;
    line-height: normal;
  }


  .weui_uploader_input_wrp {
    float: left;
    position: relative;
    margin-right: 9px;
    margin-bottom: 9px;
    width: 77px;
    height: 77px;
    border: 1px solid #D9D9D9;
  }

  .weui_uploader_hd {
    padding-top: 0;
    padding-right: 0;
    padding-left: 0;
  }

  .weui_uploader_files {
    list-style: none;
  }

  .weui_uploader_input_wrp:before {
    width: 2px;
    height: 39.5px;
  }

  .weui_uploader_input_wrp:before, .weui_uploader_input_wrp:after {
    content: " ";
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    background-color: #D9D9D9;
  }

  .weui_uploader_input {
    position: absolute;
    z-index: 1;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  }

  .weui_uploader_input_wrp:after {
    width: 39.5px;
    height: 2px;
  }

  .weui_uploader_bd {
    overflow: hidden;
  }

  .weui_cell {
    padding: 10px 15px;
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
  }

  .outstore >>> .weui-uploader_files {
    list-style: none;
    overflow-y: hidden;
  }

  .outstore >>> .weui-uploader_file {
    float: left;
    margin-right: 9px;
    margin-bottom: 9px;
    width: 79px;
    background: no-repeat 50%;
    background-size: cover;
  }

  .weui-cell.fir {
    border-top: 0;
  }

  .help {
    text-align: right;
    padding: 5px;
    font-size: 12px;
    color: #bbb;
  }

  .weui_uploader_input_wrp.inrow {
    width: 30px;
    height: 30px;
    margin: 0;
  }

  .weui_uploader_input_wrp:before {
    height: 19.5px;
  }

  .weui_uploader_input_wrp:after {
    width: 19.5px;
  }

  .weui-uploader_file.inrow {
    margin: 0;
    width: 40px;
  }

  li.weui-uploader_file {
    display: inline-block;
    padding: 3px 5px;
  }

  ul#images {
    text-align: right;
  }

  .addwrap >>> .ui.selection.dropdown {
    border: none;
  }

  .addwrap >>> .ui.dropdown .menu > .item {
    font-size: 18px;
  }

  .addwrap >>> .ui.search.dropdown > .text {
    font-size: 18px;
  }
  /*input.time {*/
  /*  border: none;*/
  /*  font-size: 16px;*/
  /*  width: 26%;*/
  /*  padding: 0 3%;*/
  /*  text-align: center;*/
  /*}*/
</style>
<template>
  <div class="addwrap">
    <div
      style="height: 50px; line-height: 50px; background: #f7f7f7; text-align: center; font-size: 16px; border-bottom: 1px solid #bdbbbc; position: relative">
      录入淀粉薯定价
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px"/>
      </a>
    </div>
    <div class="weui-cells weui-cells_form">
      <form action="" method="post" id="formid">
        <div class="cellgroup">
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">采收主体</label></div>
            <div class="weui-cell__bd">
              <input type="hidden" class="weui-input" name="orgname" :value="parta.name"/>
              <input type="hidden" name="orgguid" :value="parta.guid"/>
              <select class="weui-select" name="" v-model="parta">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in companys" :value="item">
                  {{ item.name }}
                </option>
              </select>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">部门</label></div>
            <div class="weui-cell__bd">
              <input type="hidden" name="departid" :value="depart.guid"/>
              <input type="hidden" name="departname" :value="depart.name"/>
              <select class="weui-select" v-model="depart">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in departments" :key="item.guid" :value="item">
                  {{ item.name }}
                </option>
              </select>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">单价</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input inlinput0" type="number" name="price" v-model="price" placeholder="请输入单价" />
              <input class="weui-input inlinput3" type="text" value="元/淀粉含量*吨">
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">生效日期</label></div>
            <div class="weui-cell__bd">
              <input type="text" ref="effectiveDate" id='datetime-picker' class="time" name="effectiveDate" placeholder="请选择生效日期" />
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">失效日期</label></div>
            <div class="weui-cell__bd">
              <input type="text" ref="expireDate" id='datetime-picker2' class="time" name="expireDate" placeholder="请选择失效日期" />
            </div>
          </div>
        </div>
        <div class="weui-btn-area">
          <a class="weui-btn weui-btn_primary subbtn" href="javascript:" @click="postForm()">提交</a>
        </div>
      </form>
    </div>
  </div>
</template>

<script>
  import 'vue-search-select/dist/VueSearchSelect.css'
  import {ModelListSelect} from 'vue-search-select'

  export default {
    name: 'AddMakePrice',
    data() {
      return {
        username: localStorage.username,
        userid: localStorage.userid,
        parta: '',
        companys: '',
        departments: [],
        depart: '',
        price: ''
      }
    },
    mounted() {
      let that = this;
      this.getOrgs();
      this.getDepartment();
      //根据userid和时间戳生成唯一字符串
      this.artoken = this.createToken();

      //日历初始化
      $("#datetime-picker").calendar();
      $("#datetime-picker2").calendar();
    },
    watch: {

    },
    methods: {
      getOrgs: function () {
        this.axios({
          method: 'get',
          url: '/harvest/Procurementcontract!getoRs.action',
          params: {}
        }).then(response => {
          if (response.data.msg == 'success') {
            this.companys = response.data.orgs;
          } else {
            this.toastText('获取公司数据失败')
          }
        });
      },
      getDepartment: function () {
        let that = this;
        this.axios({
          method: 'get',
          responseType: 'json',
          url: '/sales/Sellform!findDepartment.action',
          params: {sPermission: 67}
        }).then(response => {
          if (response.data.status == "true") {
            that.departments = response.data.result;
            this.depart = response.data.result[0];
          } else if (response.data.status == "false") {
            this.toastText(response.data.result);
          } else {
            this.toastText('获取部门数据失败');
          }
        });
      },
      //提交表单数据
      postForm: function () {
        let that = this;
        //表单校验
        if (!this.checkFormElm()) {
          return false;
        }
        //防止重复提交
        $('.subbtn').attr("disabled", true).css("pointer-events", "none");
        //显示提交状态
        $.showLoading("正在提交");

        let postData = this.serialize2Obj($("#formid").serializeArray());

        this.axios({
          headers: {
            'artoken': this.artoken
          },
          method: 'post',
          url: '/harvest/DpriceApply!save.action',
          params: postData
        }).then(response => {
          //恢复提交按钮可点击
          $('.subbtn').attr('disabled', false).css("pointer-events", "auto");
          //关闭提交状态
          $.hideLoading();

          if (response.data.msg == 'success') {
            this.toastSuccess("保存成功");
            this.$router.push({name: 'MakePriceList'});
          } else {
            this.toastError('系统错误');
            this.artoken = this.createToken();
          }
        }).catch(function (error) {
          //恢复提交按钮可点击
          $('.subbtn').attr('disabled', false).css("pointer-events", "auto");
          //关闭提交状态
          $.hideLoading();
          that.toastError('系统错误');
          that.artoken = that.createToken();
        });
      },
      checkFormElm: function () {
        if (this.parta == '' || this.parta == undefined) {
          this.toastText('请选择采收主体');
          return false;
        }
        if (this.depart == '' || this.depart == undefined) {
          this.toastText('请选择部门');
          return false;
        }
        if (this.price == '') {
          this.toastText('请录入价格');
          return false;
        }
        if (this.$refs.effectiveDate && this.$refs.effectiveDate.value == '') {
          this.toastText('请选择生效日期');
          return false;
        }
        if (this.$refs.expireDate && this.$refs.expireDate.value == '') {
          this.toastText('请选择失效日期');
          return false;
        }
        return true;
      }
    }
  }
</script>
